clear all
set more off 

cd "C:\Dropbox\Average_target_survey\replication_folder\dofiles"
quiet do load_rreg2

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"
use step001, clear

***collapse days when the sample size is small
gen start_day2=start_day1
recode start_day2 30/32=29

gen prob_prior=	epi_12m_12plus + epi_12m_8_12 + epi_12m_4_8

	
tempname 2
postfile `2'  str50 variable ///
	str50 E_method ///
	str12 b_heard_news ///
	str12 b_AFTER ///
	str12 b_heard_news_X_AFTER ///
	str12 R2 ///
	using "C:\Dropbox\Average_target_survey\replication_folder\outregs\AppendixTable01.dta", replace every(1)
		

		
		
* hearing news about the Fed	
gen heard_news=(QJH3==2)
gen _heard_news=(QJH3==2)*sqrt(weight)

*** condition on picking IT as the policy regime
gen IT_pick=(QJH10_2==1 | QJH10_1==1)

*** pick the right Fed target: maximum employment AND stable price
gen target=(QJH9_2==1 & QJH9_5==1)

*** post-announcement sample 
gen AFTER=(start_day2>26)  
gen _AFTER=AFTER*sqrt(weight)

*** interaction of heard_news and AFTER
gen heard_news_X_AFTER=heard_news*AFTER
gen _heard_news_X_AFTER=heard_news_X_AFTER*sqrt(weight)

*** create dummy variables for categorical variables
* education
forvalues i=2(1)6 {
	gen Q48_`i'=(Q48==`i')
	gen _Q48_`i'=(Q48==`i')*sqrt(weight)
	
}

* income
forvalues i=1(1)6 {
	gen Q49_`i'=(Q49==`i')
	gen _Q49_`i'=(Q49==`i')*sqrt(weight)
	
}

* how people get news
forvalues i=1(1)9 {
	gen _QJH1_`i'=QJH1_`i'*sqrt(weight)
}

* how often people get news
forvalues i=2(1)8 {
	gen QJH2_`i'=(QJH2==`i')
	gen _QJH2_`i'=QJH2_`i'*sqrt(weight)
}

foreach var in age male N_children married single nonwhite hispanic party_democrat party_republican party_other {
	gen _`var'=`var'*sqrt(weight)
}
local CONTROLS = " age male N_children married single nonwhite hispanic Q48_*  Q49_* QJH1_? QJH2_?  party_democrat party_republican party_other "
local _CONTROLS = " _age _male _N_children _married _single _nonwhite _hispanic _Q48_*  _Q49_*   _party_democrat _party_republican _party_other "

gen _W=sqrt(weight)
	
gen credibility = QJH17_1 if treatment_IT==0 & treatment_AIT==0
	
foreach var in 	target /// pick the right Fed target: maximum employment AND stable price
				IT_pick /// picking IT as the policy regime
				QJH11 /// Inflation target of the Fed
				epi_12m ///
				epi_12m_mean ///
				prob_prior ///
				epi_12m_std ///
				egdp_12m /// 
				edy_12m ///
				credibility /// credbility of the Fed (use only the control group)
				Q164_7 /// consumption plan Sept				
				{
		
		    
					
			capture drop Y_flag 
			gen Y_flag=(abs(`var')>20)
			
			replace Y_flag = 0 if ("`var'" == "credibility" | "`var'" == "prob_prior" | "`var'" == "Q164_7")
			replace Y_flag = 1 if "`var'" == "Q164_7" & (Q164_7 < 25 | Q164_7 > 175)
			
			capture drop _`var'
			gen _`var'=`var'*sqrt(weight)
			
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** restricted mean (exclude people outside [-20,20])
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			reg `var' heard_news AFTER heard_news_X_AFTER `CONTROLS' [aw=weight]  if Y_flag==0, robust
		
			local rb_heard_news=string(_b[heard_news],"%4.3f")
			local rb_AFTER=string(_b[AFTER],"%4.3f")
			local rb_heard_news_X_AFTER=string(_b[heard_news_X_AFTER],"%4.3f")

			local rse_heard_news="(" + string(_se[heard_news],"%4.3f") + ")"
			local rse_AFTER="(" + string(_se[AFTER],"%4.3f") + ")"
			local rse_heard_news_X_AFTER="(" + string(_se[heard_news_X_AFTER],"%4.3f") + ")"
			
			local p1=_b[heard_news]/_se[heard_news]
			local p2=_b[AFTER]/_se[AFTER]
			local p3=_b[heard_news_X_AFTER]/_se[heard_news_X_AFTER]
			
			
			if abs(`p1')>2.62 & `p1'~=. local rb_heard_news="`rb_heard_news'" + "*"
			if abs(`p2')>2.62 & `p2'~=. local rb_AFTER="`rb_AFTER'" + "*"
			if abs(`p3')>2.62 & `p3'~=. local rb_heard_news_X_AFTER="`rb_heard_news_X_AFTER'" + "*"	
			
			
			if abs(`p1')>1.98 & `p1'~=. local rb_heard_news="`rb_heard_news'" + "*"
			if abs(`p2')>1.98 & `p2'~=. local rb_AFTER="`rb_AFTER'" + "*"
			if abs(`p3')>1.98 & `p3'~=. local rb_heard_news_X_AFTER="`rb_heard_news_X_AFTER'" + "*"
			
			if abs(`p1')>1.65 & `p1'~=. local rb_heard_news="`rb_heard_news'" + "*"
			if abs(`p2')>1.65 & `p2'~=. local rb_AFTER="`rb_AFTER'" + "*"
			if abs(`p3')>1.65 & `p3'~=. local rb_heard_news_X_AFTER="`rb_heard_news_X_AFTER'" + "*"

			
			local rR2=string(e(r2),"%4.3f")
			
			post `2' ("`var'") ("restricted OLS")	("`rb_heard_news'") ("`rb_AFTER'") ("`rb_heard_news_X_AFTER'")  ("`rR2'")
			post `2' ("`var'") ("restricted OLS")	("`rse_heard_news'") ("`rse_AFTER'") ("`rse_heard_news_X_AFTER'")  ("")
			
		
			

			
}

postclose `2'


tab start_day2
